#!/usr/bin/env python

import xml.dom.minidom

class DataColumn:
    def _get_name(self):
        return self.__name
    def _set_name(self, name):
        name = name.lower()
        if (self.Schema != None):
            if (name in self.Schema):
                raise Exception()
            else:
                if (self.__name in self.Schema):
                    self.Schema.pop(self.__name)
                self.Schema[name] = self
                pass
        self.__name = name
        
    def _get_data_type(self):
        return self.__dataType
    def _set_data_type(self, dataType):
        self.__dataType = dataType

    def _get_length(self):
        return self.__length
    def _set_length(self, length):
        self.__length = int(length)

    def _get_is_key(self):
        return self.__isKey
    def _set_is_key(self, isKey):
        self.__isKey = bool(isKey)

    def _get_is_nullable(self):
        return self.__isNullable
    def _set_is_nullable(self, isNullable):
        self.__isNullable = bool(isNullable)

    def _get_schema(self):
        return self.__schema
    def _set_schema(self, schema):
        self.__schema = schema

    name = property(_get_name, _set_name)
    data_type = property(_get_data_type, _set_data_type)
    length = property(_get_length, _set_length)
    is_key = property(_get_is_key, _set_is_key)
    is_nullable = property(_get_is_nullable, _set_is_nullable)
    schema = property(_get_schema, _set_schema)
    
    def __init__(self, name, dataType = str):
        self.name = name
        self.data_type = dataType
        self.length = 0
        self.is_key = False
        self.is_nullable = True
        self.schema = None
    
    def load_file(self, filePath):
        pass
    
    def load_xml(self, xmlDom):
        if xmlDom.tagName != "DataColumn":
            raise Exception()
        
        self.name = xmlDom.getAttribute("name")
        if (xmlDom.hasAttribute("is_key")):
            self.is_key = xmlDom.getAttribute("is_key")
        
        if (xmlDom.hasAttribute("data_type")):
            self.is_key = xmlDom.getAttribute("data_type")
            
        if (xmlDom.hasAttribute("length")):
            self.is_key = xmlDom.getAttribute("length")
        
        if (xmlDom.hasAttribute("is_nullable")):
            self.is_key = xmlDom.getAttribute("is_nullable")
        
    
    def save_file(self, filePath):
        pass
    
    def save_xml(self):
        pass
